<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ include file="/taglibs.jsp"%>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script language="javascript">
	$().ready(function(){
		$("#categoryIdParam").numeric();
		$("#categoryId").numeric();
		$("#copyAll").click(function(){
			$(":input[id*=copy_]").attr('checked',$("#copyAll").attr('checked'));
		});		
		$("#editAll").click(function(){
			$(":input[id*=edit_]").attr('checked',$("#editAll").attr('checked'));
		});
		$("#delAll").click(function(){
			$(":input[id*=del_]").attr('checked',$("#delAll").attr('checked'));
		});		
		$("#searchbtn").click(function(){
			if ( $("#categoryIdParam").val() == "" ){
				alert("請輸入类别编号");
				return false;
			}
		});
		$(":input[name='copy']").click(function(){
			if ( checkData() ){
				if ( $(":checkbox[name='copyProductCategoryIds']:checked").size() == 0 ){
					alert("请选择要复制的商品编号");
					return false;
				}else{
					$("#productForm").attr("action","copyMove.do");
					return true;
				}
			}else
				return false;
		});
		$(":input[name='upd']").click(function(){
			if ( checkData() ){
				if ( $(":checkbox[name='editProductCategoryIds']:checked").size() == 0 ){
					alert("请选择要修改的商品编号");
					return false;
				}else{
					$("#productForm").attr("action","editMove.do");
					return true;
				}
			}else
				return false;	
		});		
		$(":input[name='del']").click(function(){
			if ( $(":checkbox[name='delProductCategoryIds']:checked").size() == 0 ){
					alert("请选择要删除的商品编号");
					return false;
			}else{
				$("#productForm").attr("action","delMove.do");
				return true;
			}
		});				
		$("#categoryId").blur(function(){
			$.post("<%=ServerValue.getMidContextPath()%>/productCategory/jsonCategory.do",{categoryId:$("#categoryId").val()},callback,"json");
		});
	});
	function checkData(){
		if ( "" == $("#categoryId").val() ){
			alert("请输入异动的类别编号");
			return false;
		}else if ( "该分类未上架或不存在、已被下架、删除或无该权限查看" == $("#categoryPath").text() ){
			alert($("#categoryPath").text());
			return false;
		}else if ( "请输入最底层的分类" == $("#categoryPath").text() ){
			alert($("#categoryPath").text());
			return false;
		}else if ( $("#categoryIdParam").val() == $("#categoryId").val()){
			alert("查询的类别编号与异动的类别编号相同");
			return false;
		}else return true;
	}
	function callback(categoryResult){
		if ( "failure" != categoryResult &&  "isEndnode" != categoryResult ){
			$("#categoryPath").html(categoryResult);
		}else if ( "failure" == categoryResult ){
			$("#categoryPath").html("该分类未上架或不存在、已被下架、删除或无该权限查看");
		}else if ( "isEndnode" == categoryResult ){
			$("#categoryPath").html("请输入最底层的分类");
		}		
	}
</script>
<h1>整批商品复制/修改到其他分类 -查询</h1>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<div class="data-form">
	<s:form action="searchMove.do" method="post">
		<b>类别编号：</b>
		<input name="categoryIdParam" id="categoryIdParam" type="text" title="类别编号" size="10" value="${categoryIdParam}" >
		<input type="submit" id="searchbtn" value="搜寻" />	
	</s:form>
</div>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/>
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/>
</s:if>
<br/><br/>
<font color="red">
	<ul>
		<li>※主分类可复制但不允许修改、刪除</li>
		<li>※[复制]原分类设定存在,新增一笔资料</li>
		<li>※[修改]原分类设定己不存在,只有新分类位置的设定</li>
	</ul>
</font>
<br/>
<s:form action="editMove.do" method="post" id="productForm">
请输入异动的类别编号：<s:textfield id="categoryId" name="categoryId" size="6" maxlength="6"/><span id="categoryPath">${categoryPath}</span><br/>
共： ${productCategoriesSize} 笔
<table class="tb-1" width="100%">
	<thead>
		<tr>
			<th width="10%"><input type="submit" name="copy" value="复制"/><br/>
			<input type="checkbox" id="copyAll" />全選
			</th>
			<th width="10%"><input type="submit" name="upd" value="修改"/><br/>
			<input type="checkbox" id="editAll" />全選
			</th>
			<th width="10%"><input type="submit" name="del" value="删除"/><br/>
			<input type="checkbox" id="delAll" />全選
			</th>			
			<th width="15%">商品图</th>
			<th width="15%">商品编号</th>
			<th width="45%">商品名称</th>
		</tr>
	</thead>
	<tbody>
		<c-rt:choose>
			<c-rt:when test="${not empty productCategories}">
				<c-rt:forEach items="${productCategories}" var="productCategory" varStatus="index">
					<tr>
						<td>
							<input type="checkbox" id="copy_${index.count}" name="copyProductCategoryIds" value="${productCategory[0]}"/>
						</td>
						<td>
							<c-rt:choose>
								<c-rt:when test="${productCategory[4] ne categoryIdParam}">
									<input type="checkbox" id="edit_${index.count}" name="editProductCategoryIds" value="${productCategory[0]}"/>
								</c-rt:when>
								<c-rt:otherwise>
								主分类
								</c-rt:otherwise>
							</c-rt:choose>
						</td>
						<td>
							<c-rt:choose>
								<c-rt:when test="${productCategory[4] ne categoryIdParam}">
									<input type="checkbox" id="del_${index.count}" name="delProductCategoryIds" value="${productCategory[0]}"/>
								</c-rt:when>
								<c-rt:otherwise>
								主分类
								</c-rt:otherwise>
							</c-rt:choose>
						</td>						
						<td><img onError="this.src='/PImg/blank_75.gif'" src="/PImg/${fn:substring(productCategory[1],0,4)}/${productCategory[1]}/${productCategory[1]}_m75.jpg"/></td>
						<td>${productCategory[1]}</td>
						<td>${productCategory[3]}</td>
					</tr>
				</c-rt:forEach>
			</c-rt:when>
			<c-rt:otherwise>
				<tr>
					<td colspan="5">查无商品资料</td>
				</tr>
			</c-rt:otherwise>
		</c-rt:choose>
	</tbody>
	<thead>
		<tr>
			<th width="10%"><input type="submit" name="copy" value="复制"/></th>
			<th width="10%"><input type="submit" name="upd" value="修改"/></th>
			<th width="10%"><input type="submit" name="del" value="删除"/></th>
			<th width="15%">商品图</th>
			<th width="15%">商品编号</th>
			<th width="45%">商品名称</th>
		</tr>
	</thead>	
</table>
</s:form>